export default {
    data() {
        return {
            userInfo: {}
        }
    },
    methods: {
        async getUserInfo(info) {
            const { needLoading = true, needReloadUserInfo = true, callback } = info
            if (!needReloadUserInfo) {
                const userInfo = this.$comFun.getUserInfo()
                if (userInfo) {
                    this.userInfo = userInfo;
                    if (callback) {
                        callback(this.userInfo)
                    }
                    return
                }
            }
            if (needLoading) this.$comFun.openLoading();
            const res = await this.$request.get('user/userInfo', {});
            if (needLoading) this.$comFun.closeLoading();
            if (res.code == 200) {
                this.userInfo = res.result;
                this.$comFun.setUserInfo(this.userInfo)
                if (callback) {
                    callback(res.result)
                }
            }
        },
        reloadUserInfo(info) {
            this.userInfo = {
                ...this.userInfo,
                ...info
            }
            this.$comFun.setUserInfo(this.userInfo)
        },
        jumpPage({ url, data, info }) {
            if (info?.needRealname) {
                if (this.userInfo && !this.userInfo?.cardId) {
                    this.$comFun.toast("请先进行实名认证")
                    return
                }
            }
            if (!url) {
                this.$comFun.toast("敬请期待")
                return
            }
            this.$comFun.openWin(url, data)
        },
    }
}
